<html>
<head><meta charset="utf-8"><title>Closure pretty print project-rfc-2229#15 · t-compiler/wg-rfc-2229 · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/index.html">t-compiler/wg-rfc-2229</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html">Closure pretty print project-rfc-2229#15</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="207093303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093303">(Aug 16 2020 at 22:37)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span>  is there a way of checking if it is safe to access typechk tables? </p>
<p>This fails if an error is thrown from typechk because of a cycle<br>
<a href="https://github.com/rust-lang/rust/commit/c1afd5f84ed88daf895a2e07ef1359ef3c408265#diff-e1e954c4fe23b5f47284eac19ad57a69R496">https://github.com/rust-lang/rust/commit/c1afd5f84ed88daf895a2e07ef1359ef3c408265#diff-e1e954c4fe23b5f47284eac19ad57a69R496</a> </p>
<p>eg: <a href="https://github.com/rust-lang/rust/commit/ba290defd4aa68cdf2453787465212a6df23e362">https://github.com/rust-lang/rust/commit/ba290defd4aa68cdf2453787465212a6df23e362</a></p>
<p>This is for <a href="https://github.com/rust-lang/project-rfc-2229/issues/15">https://github.com/rust-lang/project-rfc-2229/issues/15</a>, which niko suggested we should do before <a href="https://github.com/rust-lang/project-rfc-2229/issues/4">https://github.com/rust-lang/project-rfc-2229/issues/4</a> since it might require an MCP or at least pinging <code>@Esteban Küber</code></p>



<a name="207093309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093309">(Aug 16 2020 at 22:37)</a>:</h4>
<p>ughhhhh</p>



<a name="207093312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093312">(Aug 16 2020 at 22:38)</a>:</h4>
<p>I hate Zulip</p>



<a name="207093350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093350">(Aug 16 2020 at 22:38)</a>:</h4>
<p>I just nuked 50 mentions just to get here</p>



<a name="207093352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093352">(Aug 16 2020 at 22:38)</a>:</h4>
<p>woops</p>



<a name="207093357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093357">(Aug 16 2020 at 22:38)</a>:</h4>
<p>you should never query anything as needy as typeck from printing</p>



<a name="207093360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093360">(Aug 16 2020 at 22:38)</a>:</h4>
<p>it will just never end up well</p>



<a name="207093365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093365">(Aug 16 2020 at 22:39)</a>:</h4>
<p>printing captures in the closure type was a mistake anyway</p>



<a name="207093373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093373">(Aug 16 2020 at 22:39)</a>:</h4>
<p>Do you suggest just removing it?</p>



<a name="207093375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093375">(Aug 16 2020 at 22:39)</a>:</h4>
<p>I'd talk it over with <span class="user-mention" data-user-id="116009">@nikomatsakis</span></p>



<a name="207093418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093418">(Aug 16 2020 at 22:40)</a>:</h4>
<p>Aight, I'll bring it up tomorrow, thanks</p>



<a name="207093430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093430">(Aug 16 2020 at 22:41)</a>:</h4>
<p>the current way closures are printed is far from ideal for many reasons, the only problem with just printing <code>mod::nested_mod::function::{closure}</code> is disambiguating multiple closures, but maybe there's a way to throw that in there nicely</p>



<a name="207093433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093433">(Aug 16 2020 at 22:41)</a>:</h4>
<p>e.g. <code>{closure at file.rs:LL:CC}</code></p>



<a name="207093478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093478">(Aug 16 2020 at 22:42)</a>:</h4>
<p>we already have to print closure path components e.g. if you have any definition inside a closure</p>



<a name="207093492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093492">(Aug 16 2020 at 22:42)</a>:</h4>
<p>as for problems the current strategy creates: <span class="user-mention" data-user-id="116107">@davidtwco</span> had trouble trying to debug polymorphization due to how the generics of the parent not being printed at all</p>



<a name="207093513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093513">(Aug 16 2020 at 22:43)</a>:</h4>
<p>What do you mean by generics of the parent?</p>



<a name="207093583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093583">(Aug 16 2020 at 22:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/189812-t-compiler.2Fwg-rfc-2229/topic/tupled.20upvar.20types.20.2357482/near/207093433">said</a>:</p>
<blockquote>
<p>e.g. <code>{closure at file.rs:LL:CC}</code></p>
</blockquote>
<p><del>Does span have this information</del></p>



<a name="207093602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207093602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207093602">(Aug 16 2020 at 22:45)</a>:</h4>
<p>It does seem to print that <code>return type of closure is [closure@$DIR/issue-53432-nested-closure-outlives-borrowed-value.rs:4:9: 4:15]</code></p>



<a name="207121495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207121495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207121495">(Aug 17 2020 at 09:11)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> yeah but it's not printing <code>mod::nested_mod::function::</code> or whatever</p>



<a name="207121528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207121528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207121528">(Aug 17 2020 at 09:11)</a>:</h4>
<p>as for generics of the parent I mean the X, Y, Z in <code>function::&lt;X, Y, Z&gt;::{closure}</code></p>



<a name="207121576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207121576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207121576">(Aug 17 2020 at 09:12)</a>:</h4>
<p>without printing the parent path, you can't really print the substs for parent generics anywhere</p>



<a name="207157444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207157444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207157444">(Aug 17 2020 at 15:27)</a>:</h4>
<p>I see what you mean</p>



<a name="207185284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207185284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207185284">(Aug 17 2020 at 19:13)</a>:</h4>
<p>Moved the discussion to it's own topic.</p>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> <br>
For <a href="https://github.com/rust-lang/project-rfc-2229/issues/15">https://github.com/rust-lang/project-rfc-2229/issues/15</a> we would need access to typechk tables to print precise closure captures. It's possible than an error is thrown from within typechk which would results in a cycle.</p>



<a name="207509905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207509905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207509905">(Aug 20 2020 at 10:52)</a>:</h4>
<p>yes</p>



<a name="207509915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207509915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207509915">(Aug 20 2020 at 10:52)</a>:</h4>
<p>this is kind of a general problem</p>



<a name="207509918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207509918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207509918">(Aug 20 2020 at 10:52)</a>:</h4>
<p>I kind of think we should not print precise close captures</p>



<a name="207509921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207509921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207509921">(Aug 20 2020 at 10:52)</a>:</h4>
<p>I think it's too much info for humans anyway</p>



<a name="207509930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207509930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207509930">(Aug 20 2020 at 10:53)</a>:</h4>
<p>(of course it's nice for debugging to be able to get info out)</p>



<a name="207509935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207509935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207509935">(Aug 20 2020 at 10:53)</a>:</h4>
<p>I guess I can look at the issue</p>



<a name="207509948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207509948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207509948">(Aug 20 2020 at 10:53)</a>:</h4>
<p>it may be that we want a <code>-Zverbose</code> thing that targets the debugging use case</p>



<a name="207509975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207509975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207509975">(Aug 20 2020 at 10:53)</a>:</h4>
<p>I do think that <em>in general</em> it'd be nice if "type prettyprinting" (i.e., non-debug-output) allowed us to pass down context</p>



<a name="207509980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207509980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207509980">(Aug 20 2020 at 10:54)</a>:</h4>
<p>rather than relying on <code>Display</code> impl</p>



<a name="207510033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207510033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207510033">(Aug 20 2020 at 10:54)</a>:</h4>
<p>but .. it's complex. we used to have that and <span class="user-mention" data-user-id="119009">@eddyb</span> heroically moved us to the current setup, idk. there's no perfect setup it seems like.</p>



<a name="207510157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207510157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207510157">(Aug 20 2020 at 10:56)</a>:</h4>
<p>did you want me to try and draw up a specific proposal <span class="user-mention" data-user-id="281950">@Aman Arora</span> ? I'd like to get <span class="user-mention" data-user-id="119031">@Esteban Küber</span>'s take I guess. I think that what I would consider is pretty printing closures like this:</p>
<div class="codehilite"><pre><span></span><code>[closure@$DIR/closure-reform-bad.rs:10:13: 10:50]
</code></pre></div>


<p>and then, if we have <code>-Zverbose</code>, maybe include the generics (all of them):</p>
<div class="codehilite"><pre><span></span><code>[closure@$DIR/closure-reform-bad.rs:10:13: 10:50&lt;T1, T2, T3&gt;]
</code></pre></div>



<a name="207510179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207510179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207510179">(Aug 20 2020 at 10:56)</a>:</h4>
<p>this would also help with <span class="user-mention" data-user-id="116107">@davidtwco</span>'s case of not being able to see the generics</p>



<a name="207510204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207510204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207510204">(Aug 20 2020 at 10:56)</a>:</h4>
<p>I don't love the <code>[closure@path:span]</code> text but I would probably not want to change it now to minimize disruption</p>



<a name="207534726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207534726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207534726">(Aug 20 2020 at 15:20)</a>:</h4>
<p>I can write something up probably by tomorrow morning. I haven't worked with generics in rustc, so I'm not sure about the feasibility -- how do we get that information? For this to work that information should not be coming from typeck results</p>



<a name="207555065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207555065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207555065">(Aug 20 2020 at 18:09)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> <span class="user-mention" data-user-id="119031">@Esteban Küber</span> <br>
<a href="https://hackmd.io/@eoq0XxJhSJ6VzuZCQM0OgA/rkuwlV3zP">https://hackmd.io/@eoq0XxJhSJ6VzuZCQM0OgA/rkuwlV3zP</a> </p>
<p><span class="user-mention" data-user-id="119009">@eddyb</span>  <span class="user-mention" data-user-id="116107">@davidtwco</span>  can you verify if that is what you meant by generics from the parent.</p>



<a name="207555616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207555616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207555616">(Aug 20 2020 at 18:14)</a>:</h4>
<p>That looks like what I’d expect. </p>
<p>I’ve not been following this work closely but if the upvars will still be in the substitutions of the closure, then seeing those in some form would be helpful (e.g. I’ve had issues with closures in the upvar tuple referring to generic parameters that I didn’t expect but you can’t see that from the pretty printing).</p>



<a name="207555860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207555860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207555860">(Aug 20 2020 at 18:16)</a>:</h4>
<p>Once typechk is complete the <code>ClosureSubsts</code> will have the tuple of capture types. Before that it will only be a single inference variable.</p>



<a name="207555959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207555959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207555959">(Aug 20 2020 at 18:17)</a>:</h4>
<p>(Diff b/w upvar and captures is that captures is the precise path being captured eg p.x, whereas upvars in the root variable eg: p)</p>



<a name="207556176"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207556176" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207556176">(Aug 20 2020 at 18:19)</a>:</h4>
<p>That makes sense - I’d find it valuable to have those shown, in whatever form they end up taking (i.e. any circumstance where I can find that two types aren’t equal and if I print them can’t see that difference, it’s frustrating)</p>



<a name="207556178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207556178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207556178">(Aug 20 2020 at 18:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281950">Aman Arora</span> <a href="#narrow/stream/189812-t-compiler.2Fwg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315/near/207555860">said</a>:</p>
<blockquote>
<p>Once typechk is complete the <code>ClosureSubsts</code> will have the tuple of capture types. Before that it will only be a single inference variable.</p>
</blockquote>
<p>Though the proposal is to not print that information (what's being captured and their type), but seems like it is already lacking information</p>



<a name="207557471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207557471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207557471">(Aug 20 2020 at 18:31)</a>:</h4>
<p><span class="user-mention" data-user-id="116107">@davidtwco</span>  do you have a example of what all information you want to be outputted? I'm not sure what type information is currently missing</p>



<a name="207558119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207558119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207558119">(Aug 20 2020 at 18:36)</a>:</h4>
<p>I’m not sure if this is helpful - but <a href="#narrow/stream/216091-t-compiler.2Fwg-polymorphization/topic/symbol.20mangling.20v0.20.E2.9C.95.20polymorphisation/near/206152008">this thread</a> describes my debugging of a scenario where I had two substitutions (from closures, IIRC) that printed the exact same yet hashed differently and don’t equal each other - hopefully that helps (later messages in that thread describe an another problem and can be ignored).</p>



<a name="207558321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207558321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207558321">(Aug 20 2020 at 18:38)</a>:</h4>
<p>In that circumstance, a closure in the upvar tuple had different parent substitutions but I had no way of knowing that from the way it got printed.</p>



<a name="207558550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207558550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207558550">(Aug 20 2020 at 18:40)</a>:</h4>
<p>So I’d like to be able to see the contents of the upvar tuple (or capture tuple) and the parent substitutions - so that the way a tuple is printed isn’t a black box - if that makes sense?</p>



<a name="207559750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207559750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207559750">(Aug 20 2020 at 18:50)</a>:</h4>
<p>I think I sort of get it, I'm trying to write out a minimal example just to confirm I understand things correctly</p>



<a name="207562047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207562047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207562047">(Aug 20 2020 at 19:10)</a>:</h4>
<p>Actually I don't think I do, the example you have doesn't have generics -- so not sure what subsitutions other than captures are being referred there.</p>
<p>I have this: <br>
<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=8ec09dda4f374be5df37433bbc5c8cdc">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=8ec09dda4f374be5df37433bbc5c8cdc</a></p>
<p>Curious if cg and cf are considered the same type or not because of different parent generics</p>



<a name="207567360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207567360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207567360">(Aug 20 2020 at 19:57)</a>:</h4>
<p>I don’t know that the exact case I spoke about could arise without polymorphization, so it might not be worth constructing a example. Something like <code>[closure@$DIR/$FOO.rs:XX:YY XX:YY (capture tuple) &lt;parent generics&gt;]</code> is basically all I’m talking about.</p>



<a name="207570458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207570458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207570458">(Aug 20 2020 at 20:27)</a>:</h4>
<p>So we do need to keep capture information. I'd add that type information won't be availble before typechk is complete i.e. until typeck results are written back and all the inference variables are resolved. </p>
<p>I'm still in the favour of using <code>-Zverbose</code> to print capture information mostly because a) the capture information is not particularly useful for end users b) capture information &gt; upvar information. And significantly greater if a closure captures several fields from a structure.</p>
<p>Following is mostly related to implementation:</p>
<p>We wanted to keep changes to the output separate from the changing tuple of inference variables to single inference variable ([#4]), but I think we should be doing this ideally with/after [#4]/[#7]. ([#7]: is closure caputre using places) </p>
<p>Reasons:</p>
<ul>
<li>Once [#4] is implemented (ignoring the test output for a min), we can deduce if typechk is done or not based on if the ClosureSubsts contains an InferenceVariable or a Tuple. If typechk is complete then we print information based on closure captures otherwise we print information from upvar_mentioned and don't include any type information. </li>
<li>Before [#7] is implemented (and maybe even minimal capture), there is no way for us to check if the code to print the precise information is working correctly. So eg: before [#7] is implemented we don't know if our code to print <code>p.x</code> is correct or not,  and might cause problems.</li>
</ul>
<p>Overall we do this in three parts:</p>
<ol>
<li>Add parent generics, that is agnostic of any work done/will be done for 2229, so ideally any changes we plan on making should not impact this. </li>
<li>Along with [#4]: print type information only after typechk. If type information is not available, just print the list of upvars_mentioned (root variables). </li>
<li>Finish [#7] and maybe [#9], print precise capture information (including types) after typechk.</li>
</ol>
<p>Questions I have:</p>
<ul>
<li>For (1), when is information about generics avaiable? Are we sure we won't enter into a typechk cycle.</li>
<li>For (2), Does the fact that we have access to a <code>ty::Closure(def_id, susbts)</code> ensure that we have finished the pass in librustc where we gather information about upvars? (My guess would be yes, based on where closures are created, but I'd like to confirm)</li>
</ul>
<p>[#4]: <a href="https://github.com/rust-lang/project-rfc-2229/issues/4">https://github.com/rust-lang/project-rfc-2229/issues/4</a><br>
[#7]: <a href="https://github.com/rust-lang/project-rfc-2229/issues/7">https://github.com/rust-lang/project-rfc-2229/issues/7</a><br>
[#9]: <a href="https://github.com/rust-lang/project-rfc-2229/issues/9">https://github.com/rust-lang/project-rfc-2229/issues/9</a></p>



<a name="207571588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207571588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207571588">(Aug 20 2020 at 20:37)</a>:</h4>
<p>If this sounds reasonable, let me know and I'll update the proposal</p>



<a name="207741777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741777">(Aug 22 2020 at 20:54)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> normally paths are printed <code>foo::Bar::&lt;T&gt;::baz::&lt;U&gt;</code></p>



<a name="207741786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741786">(Aug 22 2020 at 20:55)</a>:</h4>
<p>the <code>[closure]</code> printing is <em>very weird</em> compared to the rest of the system</p>



<a name="207741789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741789">(Aug 22 2020 at 20:55)</a>:</h4>
<p>try printing the type of something declared inside a closure. you will see what I mean</p>



<a name="207741793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741793">(Aug 22 2020 at 20:55)</a>:</h4>
<p>I would expect <code>f::&lt;String&gt;::{closure @ src/main.rs:3:13: 3:33}</code> <em>maybe</em></p>



<a name="207741808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741808">(Aug 22 2020 at 20:56)</a>:</h4>
<p>and IMO that should be the default?</p>



<a name="207741840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741840">(Aug 22 2020 at 20:56)</a>:</h4>
<p>but I'm not sure how much file info to obscure. if it's in the same file as the parent then it feels silly to even print the file name</p>



<a name="207741847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741847">(Aug 22 2020 at 20:56)</a>:</h4>
<p><code>f::&lt;String&gt;::{closure@3:13: 3:33}</code> is probably fine? not sure. harder to just "click" on (in editors with that support)</p>



<a name="207741856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741856">(Aug 22 2020 at 20:57)</a>:</h4>
<p>but also type errors will effectively never contain anything other than generics</p>



<a name="207741858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741858">(Aug 22 2020 at 20:57)</a>:</h4>
<blockquote>
<p>I don't love the [closure@path:span] text but I would probably not want to change it now to minimize disruption</p>
</blockquote>
<p>From this, I feel like adding path will be for later</p>



<a name="207741859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741859">(Aug 22 2020 at 20:57)</a>:</h4>
<p>and we can detect that the closure has fully generic parent generics</p>



<a name="207741871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741871">(Aug 22 2020 at 20:57)</a>:</h4>
<p>so we can make a decision based on that, not just <code>-Zverbose</code></p>



<a name="207741924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741924">(Aug 22 2020 at 20:59)</a>:</h4>
<p>maybe <code>-Zverbose</code> forces the format but otherwise it's based on <code>closure_substs.parent_substs() == Substs::identity_for(tcx, tcx.closure_base_def_id(closure_def_id))</code></p>



<a name="207741944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741944">(Aug 22 2020 at 20:59)</a>:</h4>
<p>I just got back home, I'll give these a read in about half-one hour</p>



<a name="207741989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207741989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207741989">(Aug 22 2020 at 21:00)</a>:</h4>
<p>so that we always print all of the information when it's not entirely predictable</p>



<a name="207754243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207754243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207754243">(Aug 23 2020 at 03:41)</a>:</h4>
<p>Sorry I got occuppied with some stuff.</p>



<a name="207754253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207754253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207754253">(Aug 23 2020 at 03:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/189812-t-compiler.2Fwg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315/near/207741789">said</a>:</p>
<blockquote>
<p>try printing the type of something declared inside a closure. you will see what I mean</p>
</blockquote>
<p>I wasn't able to replicate what you were going for here</p>



<a name="207754296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207754296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207754296">(Aug 23 2020 at 03:42)</a>:</h4>
<p>But I think I know what you want, something like output of <a href="https://doc.rust-lang.org/std/any/fn.type_name.html">https://doc.rust-lang.org/std/any/fn.type_name.html</a></p>



<a name="207754303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/207754303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#207754303">(Aug 23 2020 at 03:43)</a>:</h4>
<p>So for the closure <code>cg</code> <del>https://repl.it/repls/BlaringPushyDeclaration#src/temp.rs</del> <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=b51f9755dae2b733ae8a8bce7a5398e5">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=b51f9755dae2b733ae8a8bce7a5398e5</a>,</p>
<p>we get <code>main::temp::temp1::Test&lt;&amp;str&gt;::g&lt;i32&gt;::{{closure}}</code></p>



<a name="208179733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/208179733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#208179733">(Aug 27 2020 at 05:37)</a>:</h4>
<p>Catching up, but old relevant ticket about closure printing: <a href="https://github.com/rust-lang/rust/issues/19939">https://github.com/rust-lang/rust/issues/19939</a></p>



<a name="208180061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/208180061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#208180061">(Aug 27 2020 at 05:45)</a>:</h4>
<p>looking</p>



<a name="208180342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/208180342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#208180342">(Aug 27 2020 at 05:50)</a>:</h4>
<p>If I understand correctly, all closures are unboxed now? </p>
<p>What's interesting is that if I go put this line a piece of code that is more involved, I get a much cleaner output. Eg check <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=33a65b0995a38063e49fd01c630ac333">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=33a65b0995a38063e49fd01c630ac333</a></p>



<a name="208180482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/208180482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#208180482">(Aug 27 2020 at 05:54)</a>:</h4>
<p>Actually never mind, in my other test I copied the code sample as is from the issue and the error I was seeing was the comment in the issue and not something the compiler was outputting. <span aria-label="joy" class="emoji emoji-1f602" role="img" title="joy">:joy:</span></p>
<p>I think the issue can be closed, the only improvement we can do is that we report both the error about param missing name and the fact that we were expecting unit type and got closure at the same time. Benefit of this would be that the user can go fix their code at once.</p>



<a name="208331609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/208331609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#208331609">(Aug 28 2020 at 11:41)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> just <code>|| { struct Foo; let () = Foo; }</code> should be enough, sorry I didn't give an example</p>



<a name="208331649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/208331649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#208331649">(Aug 28 2020 at 11:41)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=ce86ba032761dda95cb24afd1860c39f">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=ce86ba032761dda95cb24afd1860c39f</a></p>



<a name="208331920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/208331920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#208331920">(Aug 28 2020 at 11:44)</a>:</h4>
<p>that prints <code>main::{{closure}}#0::Foo</code></p>



<a name="208332036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/208332036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#208332036">(Aug 28 2020 at 11:45)</a>:</h4>
<p>I guess your example is better because it observes the case when there's generics of the parent being applied)</p>



<a name="208332648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/208332648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#208332648">(Aug 28 2020 at 11:52)</a>:</h4>
<p>although <code>type_name</code> uses a special printer which avoids most of the "fancy" printing codepaths</p>



<a name="208526298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/208526298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#208526298">(Aug 31 2020 at 07:12)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> <br>
Sorry I got occupied a little last couple of days. I get what you mean now. </p>
<p>From what I understand is, printing the path to the closure when printing a type defined within it, is already implemented, which can then be reused here.</p>
<p>Also curious if we will even print type of the closure not near it, mostly wondering other than needing to print generics nicely do we need actually print the path? </p>
<hr>
<p>Regarding <a href="https://github.com/rust-lang/rust/issues/70334#issuecomment-682483007">https://github.com/rust-lang/rust/issues/70334#issuecomment-682483007</a>, If I understand correctly, it feels like most of this will be in a different part of the codebase. </p>
<p>Also, the main goal of changing how closure print as part of 2229 is to make sure that we have tests passing when we change the capture tuple to be an inference variable and also to making sure the information is correct once we start capturing paths to member fields.</p>



<a name="208777282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/208777282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#208777282">(Sep 02 2020 at 04:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/189812-t-compiler.2Fwg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315/near/208332648">said</a>:</p>
<blockquote>
<p>although <code>type_name</code> uses a special printer which avoids most of the "fancy" printing codepaths</p>
</blockquote>
<p>What do you mean by _fancy_ here?</p>



<a name="211507871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/Closure%20pretty%20print%20project-rfc-2229%2315/near/211507871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/Closure.20pretty.20print.20project-rfc-2229.2315.html#211507871">(Sep 28 2020 at 15:27)</a>:</h4>
<p>Davidtwco suggested that we use a different flag than verbose to do verbose printing for closures<br>
<a href="https://github.com/rust-lang/rust/pull/77069#discussion_r493458704">https://github.com/rust-lang/rust/pull/77069#discussion_r493458704</a></p>
<p>I'm fine either way, what are your thoughts <span class="user-mention" data-user-id="116009">@nikomatsakis</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>